<?php
/**
 * Created by PhpStorm.
 * User: Soha_Ros
 * Date: 17/6/11
 * Time: 下午4:26
 */

namespace ActionsHttp;


use Data\Restaurant_DAO;
use Data\Restaurant_settings_sound;
use Data\Restaurant_settings_sound_DAO;

class RestaurantSettingsRingSet extends BaseActionHttp
{
    public function doAction() {

        parent::doAction();

        // 商铺id
        $restaurant_id = $_SESSION[RESTAURANT_ID];
        $restaurant_id = 1;

        $restaurant_record = Restaurant_DAO::getRecord($restaurant_id);

        if (!$restaurant_record) {
            return $this->SendErrMsg("没有该商铺");
        }

        $is_ring = $this->data[IS_RING];

        $is_vibration = $this->data[IS_VIBRATION];


        $restaurant_settings_ring_record = Restaurant_settings_sound_DAO::getRecord($restaurant_id);

        if (!$restaurant_settings_ring_record) {

            $restaurant_settings_ring_record = new Restaurant_settings_sound(array());

            $restaurant_settings_ring_record->setRESTAURANT_ID($restaurant_id);

            $restaurant_settings_ring_record->setIS_RING($is_ring);

            $restaurant_settings_ring_record->setIS_VIBRATION($is_vibration);

            // 插入
            Restaurant_settings_sound_DAO::insert($restaurant_settings_ring_record);

        } else {

            $restaurant_settings_ring_record->setIS_RING($is_ring);

            $restaurant_settings_ring_record->setIS_VIBRATION($is_vibration);

            // 更新
            Restaurant_settings_sound_DAO::update($restaurant_settings_ring_record);

        }

        // 返回数据
        $this->ResponseDataToCurrentClient();

    }
}